

$(function(){
	$(".h_nav a").mouseenter(function(){	
	    $(".h_nav_down").css("opacity",0);
		$(".h_nav_down").eq($(this).index()).css("opacity",1);
	});
	// $(".h_nav down").mouseenter(function(){		  
	// 	$(this).css("opacity",1);
	// });

	// $(".h_nav a").mouseleave(function(){	 		
	// 	$(".h_nav_down").css("opacity",0);
	   
	// });
	// $(".h_nav down").mouseleave(function(){	
	//     $(".h_nav_down").css("opacity",0);
	// });
	// $(".h_top_span").mouseenter(function(){
	// 	$(this).find('img').attr('src','')
	// }
	console.log(2);
	$(window).on('scroll',function(){
		console.log(document.body.scrollTop);
		if(document.body.scrollTop >= 150){
			console.log(1);
            $(".h_top").hide();
            $(".h_middle").hide();
            $(".h_nav").css('position',"fixed").css('z-index',"5").css('width',document.documentElement.clientWidth);
        }else{
           $(".h_top").show();
            $(".h_middle").show();
            $(".h_nav").css('position',"relative").css('z-index',"5");
        }
	})
})
	

function dataFn(a,fun){
	 	    var ApplicationId = "65e55920bf1116b961d211de08eaef6c";
			var ApiKey = "0c4571f8cbd8344f7ed365ef39645f67";
			Bmob.initialize(ApplicationId,ApiKey);
			var List = Bmob.Object.extend(a);
			var query = new Bmob.Query(List);

			query.find({
				success:function(data){
					fun(data);
				}

			})
 	    };
 angular.module("myApp",["ngRoute"])
.config(["$routeProvider",function($routeProvider){
	$routeProvider
	.when("/",{templateUrl:"shouye.html",controller:"shouye"})
	.when("/product0",{templateUrl:"product.html",controller:"product"})
	.when("/product1",{templateUrl:"p_top.html",controller:"product"})
	.when("/product2",{templateUrl:"p_work.html",controller:"product"})
	.when("/product3",{templateUrl:"p_chair.html",controller:"product"})
	.when("/product4",{templateUrl:"p_public.html",controller:"product"})
	.when("/case0",{templateUrl:"case.html",controller:"case"})
    .when("/eat0",{templateUrl:"eat.html",controller:"eat"})
    .when("/new0",{templateUrl:"new.html",controller:"new"})
    .when("/me0",{templateUrl:"me.html",controller:"me"})

}])
 .controller("myCtrl",["$scope","$rootScope","$http",function($scope,$rootScope,$http){
      //导航栏列表
      $rootScope.name = [{"href":"#/product0","name":"高管行政区"},
	                         {"href":"#/product1","name":"开放办公区"},
	                         {"href":"#/product2","name":"会议/培训"},
	                         {"href":"#/product3","name":"座椅"},
	                         {"href":"#/product4","name":"公共空间"}];
 }])
// 首页控制器
 .controller("shouye",["$scope","$rootScope","$http",function($scope,$rootScope,$http){
// 配置图表
 		   var myChart = echarts.init(document.getElementById('mains'));
	        // 指定图表的配置项和数据
	        var option = {
	            title: {
	                text: 'ECharts 入门示例'
	            },
	            tooltip: {},
	            legend: {
	                data:['销量']
	            },
	            xAxis: {
	                data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
	            },
	            yAxis: {},
	            series: [{
	                name: '销量',
	                type: 'bar',
	                data: [5, 20, 36, 10, 10, 20]
	            }]
	        };

	        // 使用刚指定的配置项和数据显示图表。
	        myChart.setOption(option);
// 配置地图
            var map = new AMap.Map('container',{
	            resizeEnable: true,
	            zoom: 10,
	            center: [116.397428, 39.90923]
	        });

//配置数据库,
 	    dataFn("json1",function(data){
 	    	 $scope.$apply(function(){
				$scope.data = data;
			})
 	    });
 	     dataFn("json2",function(data){
 	    	 $scope.$apply(function(){
				$scope.data2 = data;
			})
 	    });


 	
 	   
 	   $scope.sy_eee_five_top = function(){
 	   	   var inde = this.$index;
 	   	   $(".sy_repeat_show").css("opacity","0");
 	   	   $(".sy_repeat_show").eq(inde).css("opacity","1");
            
 	   }

  }])
.controller("product",["$scope","$rootScope","$http",function($scope,$rootScope,$http){
 
 	

 	     dataFn("json3",function(data){
 	    	 $scope.$apply(function(){
				$scope.p_picture = data;
				// 改变type指向
				data.forEach(function(e){					
					if (e) {
						e.type = e.attributes.type;
					};
					// console.log(e);
				})

                $scope.p_top = data.slice(0,12);
                $scope.p_open = data.slice(12,21);
                $scope.p_work = data.slice(21,30);
                $scope.p_chair = data.slice(30,48);
                $scope.p_public = data.slice(48,60);

			})
 	    });
 	    
 	     $scope.prop = '';
         $scope.type1 = function(){
         	$scope.prop = 1;
         };
         $scope.type2 = function(){
         	$scope.prop = 2;
         };
         $scope.type3 = function(){
         	$scope.prop = 3;
         };
       
}])
// case控制器
.controller("case",["$scope","$rootScope","$http",function($scope,$rootScope,$http){
        dataFn("json2",function(data){
 	    	 $scope.$apply(function(){
 	    	 	data.forEach(function(e){					
					if (e) {
						e.user = e.attributes.user;
					};
				})
				$scope.cases = data;
			})
 	    });
       

 	
        // repeat


        $scope.props = 1;       
        $('.c_span2 li').click(function(){
        	$scope.props = $(this).index()+1;
        });
       

}])
// eat控制器
.controller("eat",["$scope","$rootScope","$http",function($scope,$rootScope,$http){
      
}])
// new控制器
.controller("new",["$scope","$rootScope","$http",function($scope,$rootScope,$http){
      $scope.names = 5;
      dataFn("json4",function(data){
 	    	 $scope.$apply(function(){
 	    	 	data.forEach(function(e){					
					if (e) {
						e.user = e.attributes.user;
					};
				})
				$scope.news = data;
				$scope.news1 = data.slice(0,6);
				$scope.news2 = data.slice(6,12);
				$scope.news3 = data.slice(12,18);
				$scope.news4 = data.slice(18,23);
				// 封装页数函数
				$scope.yeshu = function(a){
					var index = a;
                    return Math.ceil(index.length/6);
				};
				// 初始化页数
				$scope.pages = $scope.yeshu($scope.news);
				 for (var i = 1; i <= $scope.pages; i++) {	
					$(".n_fenye li").eq(i-1).after($("<li></li>").html('<div ng-click="ye()">'+i+'</div>'));
				 };
				 $scope.change = $scope.news1;
                 var changArr = [$scope.news1,$scope.news2,$scope.news3,$scope.news4];
                 var ind = 0;
                 $(".n_fenye li").eq(ind+1).find('div').css('color','#fc904e');
                 console.log($(".n_fenye li").eq(ind+1));
				 $scope.chang = function(){
				 	 ind++;
				 	 if(ind > 3){
				 	 	ind = 3;
				 	 };
                     $scope.change = changArr[ind];
                     $(".n_fenye").find('div').css('color','gray');
                     $(".n_fenye li").eq(ind+1).find('div').css('color','#fc904e');
				 };
				  $scope.shouye = function(){
				  	 ind = 0;
                     $scope.change = changArr[ind];
                     $(".n_fenye").find('div').css('color','gray');
                     $(".n_fenye li").eq(ind+1).find('div').css('color','#fc904e');

				 };
				  $scope.moye = function(){
				  	 ind = changArr.length - 1;
                     $scope.change = changArr[ind];
                     $(".n_fenye").find('div').css('color','gray');
                     $(".n_fenye li").eq(ind+1).find('div').css('color','#fc904e');
				 };
				 $scope.ye = function(){
				  	 ind = $(this).index()-1;
                     $scope.change = changArr[ind];
                     $(".n_fenye").find('div').css('color','gray');
                     $(".n_fenye li").eq(ind+1).find('div').css('color','#fc904e');
				 };
			})
 	    });
        

 	



}])
// me控制器
.controller("me",["$scope","$rootScope","$http",function($scope,$rootScope,$http){
      
}])
	
	


